const labels = document.querySelectorAll('.form-control label')

labels.forEach(label => {
    label.innerHTML = label.innerText
        .split('')
        .map((letter, idx) => `<span style="transition-delay:${idx * 50}ms">${letter}</span>`)
        .join('')
})

const loginButton=document.getElementById("login")
loginButton.addEventListener("click",function(){
    console.log("hello")
    login()
})








// 以下是函数
async function login(){
    const accountInput=document.getElementById("account")
    const passwordInput=document.getElementById("password")
    const isAdminCheckbox=document.getElementById("isAdmin")
    let level
    if (isAdminCheckbox.checked===true){
        level=1
    }else{
        level=2
    }
    console.log(accountInput.value,isAdminCheckbox.checked,passwordInput.value)
    const url = `${config.server}`+"/api/admin/login";
    const data={
        "account":accountInput.value,
        "password":passwordInput.value,
        "level":level
    }
    const response=await fetch(url,{
        method:"POST",
        headers: { 'Content-Type': 'application/json' },
        body:JSON.stringify(data)
    })
    const getdata= await response.json()
    if(!response.ok){
        alert("登录失败",getdata)
        return
    }
    localStorage.setItem("token",getdata.token)
    window.location.href="../../index.html"
}
